package com.hjqjl.whdemo.feature.feature0.ui.activity.custom;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivityGame2048Binding;
import com.hjqjl.whdemo.widget.view2048.Game2048Layout;

/**
 * 2048游戏控件
 * 参考http://blog.csdn.net/lmj623565791/article/details/40020137
 */

public class Game2048Activity extends BaseActivity {

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, Game2048Activity.class);
        context.startActivity(intent);
    }

    private ActivityGame2048Binding binding;

    @Override
    protected void initData() {
        binding = ActivityGame2048Binding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        binding.viewGame2048Game2048Layout.setOnGame2048Listener(new Game2048Layout.OnGame2048Listener() {
            @Override
            public void onScoreChange(int score) {
                binding.tvGame2048Score.setText("SCORE: " + score);
            }

            @Override
            public void onGameOver() {
                new AlertDialog.Builder(pActivity).setTitle("GAME OVER")
                        .setMessage("YOU HAVE GOT " + binding.tvGame2048Score.getText())
                        .setPositiveButton("RESTART", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                binding.viewGame2048Game2048Layout.restart();
                            }
                        }).setNegativeButton("EXIT", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).show();
            }
        });
    }

    @Override
    protected void processLogic() {

    }
}
